{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e6deda8d-953a-46e8-985d-58440ffaa167",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Note: you may need to restart the kernel to use updated packages.\n"
     ]
    }
   ],
   "source": [
    "# Install the package\n",
    "%pip install --upgrade --quiet  dashscope\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "c235ab40-95e6-4737-97cb-d34099c9a2b8",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "os.environ[\"DASHSCOPE_API_KEY\"] = 'sk-84bdfb20aeea468e813695c5887933b3'\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "c8486957",
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain.chains import LLMChain\n",
    "from langchain.prompts import PromptTemplate\n",
    "from langchain_community.llms import Tongyi\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "ff5792c9",
   "metadata": {},
   "outputs": [],
   "source": [
    "template = \"\"\"Question: {question}\n",
    "\n",
    "Answer: Let's think step by step.\"\"\"\n",
    "\n",
    "prompt = PromptTemplate.from_template(template)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "51730024",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'question': '你是谁?', 'text': '我是来自阿里云的大规模语言模型，我叫通义千问。'}"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "llm = Tongyi()\n",
    "llm_chain = LLMChain(prompt=prompt, llm=llm)\n",
    "question = \"你是谁?\"\n",
    "\n",
    "llm_chain.invoke(question)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
